View

Section: ET++ class description (n)
Updated: automatically Mon Apr 8 20:17:22 1991
Index Return to Main Contents
 

NAME

View.short - abstract drawing surface and clipboard operations  

DESCRIPTION

The abstract class View provides a drawing surface of arbitrary size to render and print the data structures of an application. In addition, View maintains a current selection and exchanges data with other Views via the clipboard.


Document and Views


Views are usually created in the method Document::DoMakeWindows. A document may have any number of Views showing the document's data in different representations.
A View is usually not directly installed in a window, rather it is put into a Clipper or Scroller in order to show only a part of reasonable size and to allow scrolling. By installing a View in a Splitter or in more than one Scroller different portions of the View can be displayed simultaneously. For example:


Window *MyDocument::DoMakeWindows()
{
    View *view1 = new MyView1 (this /* the next handler */, /* data */);

    return new Window (this, Point(600,800), eWinDefault,
               new Expander (cIdNone, eVert, gPoint2,
                   new Scroller (view1),        // show view1 in 2 Scrollers
                   new Scroller (view1),        // simultaneously
                   new Splitter (new MyView2 (this, /* data */)),
                   NULL
               )
           );
}


A document is always the next event handler of its Views. A View processes user input and passes command objects along the event handler chain to the document. The document executes these commands and this way modifies its data. Dividing the work of displaying, input handling and storing the data is a common practice in ET++ applications and conforms to the MVC (Model-View-Controller) concept introduced by SmallTalk.


Selection and Clipboard


View maintains a current selection. The current selection is a part of the data shown by the View, e.g. a range of text or an element of a list of objects. Commands such as cut, copy and paste are always applied to the current selection. The current selection is additionally drawn highlighted (see Drawing and Selection Highlighting below).
The clipboard is a kind of store where a View can deposit its current selection. Copies of the selection can later be used by the same or by other Views. The cut, copy and paste commands use the clipboard mechanism to exchange data between different Views and even between Views of different applications.
The current selection can be cut or copied to the clipboard and the contents of the clipboard can be pasted into the data structure of the View. Subclasses of View implement cut and copy by overriding the method HasSelection and the method SelectionToClipboard. The paste command can be implemented by overriding the method CanPaste and the method PasteData. HasSelection and CanPaste are actually only used to setup the cut, copy and paste menu items. A good example for implementing the clipboard operations can be found in the class TextView.


Drawing and Selection Highlighting


Drawing and highlighting the current selection is done by overriding the method Draw. For example, a View showing a list of VObjects would implement Draw like this:


class MyView : public View {
    Collection *list;          // a list of VObjects
    VObject *selected;         // currently selected VObject of the list
public:
    ....
    void Draw (Rectangle);
};

void MyView::Draw (Rectangle rect)
{
    Iter next(list);
    VObject *vop;
    while (vop = (VObject*) next())
    {
        bool highlight = (vop == selected);
        vop->DrawAll(rect, highlight);  // draw highlighted if it is selected
    }
}


The method Update is called before the actual drawing is done. Update gives the possibility to update the View, e.g. to recalculate its layout. See the method DialogView::Update for an example.


classes are always derived from View.
class View is never reused directly.
class View is abstract.
class View contains 30 methods.

owner of class:
nobody.
baseclasses:
VObject
subclasses:
CollectionView, DialogView, StaticTextView
flags:
ViewFlags

 

INSTANCE VARIABLES

clippers (private SeqCollection *)
contains all Clippers that show this View. Scrolling, invalidation and drawing methods of the View are not only forwarded to the normal container, but to all Clippers in this list. This allows to display a View simultaneously in more than one Clipper. The first Clipper in this list is identical with the instvar VObject::container.
clippers is modified by the method AddToClipper and the method RemoveFromClipper. It can be accessed with the method GetClipperList.

focus (protected Clipper *)
contains the Clipper which currently has the input focus. focus refers to the focus Clipper only when an event is processed. If focus is set, then scrolling methods are forwarded only to that Clipper instead of passing them to all Clippers in the instvar clippers. See also the method Input.

nexthandler (private EvtHandler *)
is the next event handler returned by the method GetNextHandler. It is specified in the constructor but can also be set with the method SetNextHandler. The nexthandler usually refers to the Document that created the View in its DoMakeWindows method.

 

INSTANCE METHOD LIST

client interface
GetClipperList
GetDocument

clipboard
CanPaste
HasSelection
PasteData
SelectionToClipboard

drawing
DrawAll
ShowInAllClippers

event handling
DoCursorKeyCommand
DoFunctionKeyCommand
Input
SetNextHandler

implementation
AddToClipper
CheckOpen
GetNextHandler
GetViewedRect
RemoveFromClipper
SetExtent
~View

invalidation
InvalidateRect

menus
DoCreateMenu
DoMenuCommand
DoSetupMenu

miscellaneous
InspectorId

overrider interface
Update
View

scrolling
ConstrainScroll
RevealAlign
RevealRect
Scroll

 

CATEGORIES

Application Framework

 

FILES

declaration:
View.h

 

KNOWN PROBLEMS

See method ShowInAllClippers.  

HISTORY

joe@csesbg.at  Wed Apr 17 15:25 1991   first version

joe@csesbg.at  Tue Jun 25 19:51 1991   reworked

gil@csesbg.at  Tue Jul 09 13:00 1991   reviewed

chris@csesbg.at        Wed Jul 10 09:00 1991   reviewed


 

Index

NAME
DESCRIPTION
INSTANCE VARIABLES
INSTANCE METHOD LIST
CATEGORIES
FILES
KNOWN PROBLEMS
HISTORY

This document was created by man2html, using the manual pages.
Time: 00:40:21 GMT, March 30, 2022